package com.zhaoxi.project.sys.controller;

import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.project.sys.service.Example3Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

// * 样例信息操作处理
@RestController
@RequestMapping("/sys/example3")
public class Example3Controller extends BaseService {
  @Autowired
  private Example3Service exampleService;

  //  获列表
  @PreAuthorize("@ss.hasPermi('sys:example:list')")
  @GetMapping("/getList")
  public PageData getList(Map map) {
    PageData pd = this.getPageData(map);
    //如果 pageNum 和 pageSize 都是有值的，就是需要分页的
    if (pd.getLong("pageNum") != null && pd.getLong("pageSize") != null){
      this.startPage();
    }
    return  exampleService.getList(pd);
  }

  //  获行数
  @PreAuthorize("@ss.hasPermi('sys:example:list')")
  @GetMapping("/getCount")
  public PageData getCount(Map map) {
    PageData pd = this.getPageData(map);
    return exampleService.getCount(pd);
  }

  //  新增
  @PreAuthorize("@ss.hasPermi('sys:example:add')")
  @Log(title = "样例管理", businessType = BusinessType.INSERT)
  @PostMapping
  public PageData add(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return  exampleService.add(pd);
  }

  //  修改
  @PreAuthorize("@ss.hasPermi('sys:example:edit')")
  @Log(title = "样例管理", businessType = BusinessType.UPDATE)
  @PutMapping
  public PageData edit(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return exampleService.edit(pd);
  }

  //  删除
  @PreAuthorize("@ss.hasPermi('sys:example:del')")
  @Log(title = "样例管理", businessType = BusinessType.DELETE)
  @DeleteMapping("id/{id}")
  public PageData del(@PathVariable Long id) {
    return exampleService.del(id);
  }

  //============子表数据增删改查================
  //  获列表
  @PreAuthorize("@ss.hasPermi('sys:example:list')")
  @GetMapping("/getLineList")
  public PageData getLineList(Map map) {
    PageData pd = this.getPageData(map);
    //如果 pageNum 和 pageSize 都是有值的，就是需要分页的
    if (pd.getLong("pageNum") != null && pd.getLong("pageSize") != null){
      this.startPage();
    }
    return this.responses(exampleService.getLineList(pd));
  }

  //  删除
  @PreAuthorize("@ss.hasPermi('sys:example:del')")
  @Log(title = "样例管理", businessType = BusinessType.DELETE)
  @DeleteMapping("lineId/{lineId}")
  public PageData delLine(@PathVariable Long lineId) {
    PageData pd = this.getPageData();
    pd.put("lineId",lineId);
    return exampleService.delLine(pd);
  }


  //============tree关联表数据增删改查================
  //  获列表
  @PreAuthorize("@ss.hasPermi('sys:example:list')")
  @GetMapping("/getTreeList")
  public PageData geTreeList(Map map) {
    PageData pd = this.getPageData(map);
    return this.responses(exampleService.getTreeList(pd));
  }

  //  修改
  @PreAuthorize("@ss.hasPermi('sys:example:edit')")
  @Log(title = "样例管理", businessType = BusinessType.UPDATE)
  @PutMapping("/tree")
  public PageData editTree(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return exampleService.editTree(pd);
  }
}
